from SimpylScrape.Parsers import *
from SimpylScrape.ParseDecorators import *
import urlparse
import re

class NetbookDetails(SiteParser):

    _batteryParser = re.compile(r'(\d+ Cell) Battery')

    def battery(table):
        """
        .//form[@name='SystemID']/table[3]//td
        """
        text = ' '.join(table.itertext())
        battery = NetbookDetails._batteryParser.search(text)
        if battery:
            return battery.groups()[0]
        return 'Unknown'

class DellOutlet(SiteParser):
    """
    http://outlet.us.dell.com/ARBOnlineSales/topics/global.aspx/arb/online/en/InventorySearch?c=us&cs=22&l=en&lob=INSP&MODEL_DESC=Inspiron%20Mini%2012%20-%201210&s=dfh
    """
    class netbooks(XpathParser):
        """
        .//table[@class='tblLayout']/tr/td[2]
        """

        model = ".//div[@class='point_small']/text()"
        
        price = "../td[4]/span/text()"

        def metadata(onclick):
            """
            ./a/@onclick
            """
            url = urlparse.urljoin(DellOutlet.__doc__, onclick.split("'", 2)[1]).strip()
            nd = NetbookDetails(url)
            nd()
            return nd

if __name__ == "__main__":
    d = DellOutlet()()
    d.pprint()
